var detailVue = new Vue({
	el: "#app",
	data: {
		imgUrl: imgUrl,
		product: {},
		productModels: [],
		banners: [],
		isCollect: false,
		choose: {},
		salesCount: null,
		mall_text: "请选择",
		count: 1,
		isShow: false,
		tab_opacity: 0,
		point: 1,
		mall_num: 0,
		defaultPhotoPath: "",
		evals: [],
		evalTotal:0,
		translate:0,
		picWidth:750
	},
	methods: {
		get_goods_data: function() {
			var t = this;
			var s = {};
			s.user_data = localStorage.getItem("user_data");
			// 渲染详情
			t.goods_data = t.product;
			t.productGuid = t.product.productGuid;
			var logoPath = t.product.logoPath;
			t.banners = logoPath.split(",");
			var detailPath = t.product.detailPath;
			t.goods_data2 = detailPath.split(",");
			t.productModels = t.product.productModels;
			t.choose = t.product;
			t.bannersRock(true);
			// 用户未登录
			if (s.user_data) {
				// 登录过后查看购物车
				wx.showLoading({
					title: "加载中...",
					mask: !0
				});
				this.$http.post(baseUrl + "product/is_collect", {
					productGuid: t.productGuid,
					type: 'prod'
				}).then(function(s) {
					wx.hideLoading();
					var a = s.data;
					if (a.success) {
						t.isCollect = a.data.collect;
						t.mall_num = a.data.shopCarCount;
					} else {
						wx.showToast({
							title: a.description,
							icon: "none",
							duration: 1500,
							mask: !0,
							success: function(t) {}
						});
					}
				}).catch(function() {
					wx.hideLoading(), wx.showToast({
						title: "网络错误，请检查网络",
						icon: "none",
						duration: 2e3,
						mask: !1
					});
				});
			}
		},
		changeModel: function(item) {
			var t = this;
			t.choose.originPrice = item.originPrice;
			t.choose.price = item.price;
			t.choose.points = item.points;
			t.choose.modelId = item.modelId;
			t.mall_text = item.name;
			t.salesCount = item.storeCount;
			t.productModels.forEach(function(e) {
				e.active = false;
			});
			item.active = true;
		},
		reduceCount: function() {
			var data = this;
			if (data.count == 1) {
				return;
			}
			data.count--;
		},
		addCount: function() {
			var data = this;
			if (data.count == data.salesCount) {
				return;
			}
			data.count++;
		},
		handerScroll: function() {
			var s = srollEvent.getScrollTop();
			this.tab_opacity = s / 200, s < 565 ? this.type = 1 : 565 < s && s < 900 ? this.type = 2 : s > 900 && (this.type =
					3),
				this.target = "" == this.target ? this.target : "";
		},
		go: function(id, index) {
			this.point = index;
			var element = this.$el.querySelector("#" + id);
			document.documentElement.scrollTop = element.offsetTop;
		},
		openChoose: function() {
			var t = this;
			wx.showLoading({
				title: "加载中...",
				mask: !0
			});
			this.$http.post(baseUrl + "wap/product/detail", {
				productGuid: this.productGuid
			}).then(function(s) {
				wx.hideLoading();
				var a = s.data;
				if (!a.success) return wx.showToast({
					title: a.description,
					icon: "none",
					duration: 2e3,
					mask: !0
				});
				t.productModels.forEach(function(e, index) {
					e.modelId = a.data[index].modelId;
					e.originPrice = a.data[index].originPrice;
					e.price = a.data[index].price;
					e.points = a.data[index].points;
					e.storeCount = a.data[index].storeCount;
				});
				t.isShow = true;
			}).catch(function(t) {
				wx.hideLoading(), wx.showToast({
					title: "网络错误，请稍后重试",
					icon: "none",
					duration: 2e3,
					mask: !0
				});
			});
		},
		collect: function() {
			var t = this;
			login._2page();
			if (t.isCollect) {
				this.$http.post(baseUrl + "product/remove/collect", {
					productGuid: this.productGuid
				}).then(function(a) {
					var i = a.data;
					if (i.success) {
						t.isCollect = !t.isCollect;
						wx.showToast({
							title: "取消收藏成功",
							icon: "none",
							duration: 2e3,
							mask: !1,
							success: function() {}
						})
					} else wx.showToast({
						title: i.description,
						icon: "none",
						duration: 2e3,
						mask: !1
					});
				}).catch(function(t) {
					wx.hideLoading(), wx.showToast({
						title: "网络错误，请稍后重试",
						icon: "none",
						duration: 2e3,
						mask: !0
					});
				});
			} else {
				this.$http.post(baseUrl + "product/add/collect", {
					productGuid: this.productGuid
				}).then(function(a) {
					var i = a.data;
					if (i.success) {
						t.isCollect = !t.isCollect;
						wx.showToast({
							title: "添加收藏成功",
							icon: "none",
							duration: 2e3,
							mask: !1,
							success: function() {}
						})
					} else wx.showToast({
						title: i.description,
						icon: "none",
						duration: 2e3,
						mask: !1
					});
				}).catch(function(t) {
					wx.hideLoading(), wx.showToast({
						title: "网络错误，请稍后重试",
						icon: "none",
						duration: 2e3,
						mask: !0
					});
				});
			}
		},
		call: function() {
			Jump.to(page.mine.onlineService);
		},
		addShopCar: function() {
			var s = this;
			login._2page();
			if (!this.choose.modelId) {
				wx.showToast({
					title: "请选择规格",
					icon: "none",
					duration: 2e3,
					mask: !0
				});
				return;
			}
			if (this.count > this.salesCount) {
				wx.showToast({
					title: "库存不足!",
					icon: "none",
					duration: 2e3,
					mask: !0
				});
				return;
			}
			var i = {
				modelId: this.choose.modelId,
				productGuid: this.productGuid,
				count: this.count
			};
			wx.showLoading({
				title: "加载中...",
				mask: !0
			});
			this.$http.post(baseUrl + "shopCar/add", i).then(function(t) {
				wx.hideLoading();
				var a = t.data;
				if (!a.success) return wx.showToast({
					title: a.description,
					icon: "none",
					duration: 2e3,
					mask: !0
				}), !1;
				wx.showToast({
					title: "加入购物车成功",
					icon: "none",
					duration: 2e3,
					mask: !1
				}), s.isShow=false, s.mall_num++;
			}).catch(function(t) {
				wx.hideLoading(), wx.showToast({
					title: "网络错误，请稍后重试",
					icon: "none",
					duration: 2e3,
					mask: !0
				});
			});
		},
		toShopCar: function() {
			login._2page(page.shopcar.index);
			Jump.to(page.shopcar.index);
		},
		getEvals: function() {
			var t = this;
			wx.showLoading({
				title: "加载中",
				mask: !0
			}), this.$http.post(baseUrl + "eval/list", {
				productGuid: this.product.productGuid,
				type: 'prod',
				currentPage: 1,
				pageSize: 2
			}).then(function(a) {
				wx.hideLoading();
				var i = a.data;
				if (!i.success) {
					wx.hideLoading(), wx.showToast({
						title: "网络错误，请稍后重试",
						icon: "none",
						duration: 2e3,
						mask: !0
					});
				} else {
					this.evals = i.data;
					this.evalTotal = i.total;
				}
			}).catch(function(t) {
				wx.hideLoading(), wx.showToast({
					title: "网络错误，请稍后重试",
					icon: "none",
					duration: 2e3,
					mask: !0
				});
			});
		},
		bannersRock:function(init){
			var t = this;
			if(init){
				t.left = new Array();
				var banners = this.banners;
				banners.forEach(function(e,index){
					if(index==banners.length-1){
						return;
					}
					t.left.push((index+1)*t.picWidth*-1);
				});
				t.right = new Array();
				t.flag = true;
				
			}
			t.inter = setInterval(function(){
				if(t.flag){
					t.translate = t.left.shift();
					t.right.push(t.translate);
					if(t.left.length==0){
						t.flag =false;
					}
				}else{
					var translate = t.right.pop();
					t.translate = translate+t.picWidth;
					t.left.push(translate);
					if(t.right.length==0){
						t.flag = true;
						t.left.reverse();
					}
				}
			},2000)
		},
		toEvalPage:function(){
			Jump.to(page.eval.index,"title="+this.product.name+"&type=prod&productGuid="+this.product.productGuid);
		},
		touchStart: function(ev) {
			ev = ev || event;
			ev.preventDefault();
			//                      console.log(ev.targetTouches);
			//                      console.log(ev.changedTouches);
			if (ev.touches.length == 1) { //tounches类数组，等于1时表示此时有只有一只手指在触摸屏幕
				this.startX = ev.touches[0].clientX; // 记录开始位置
			}
		},
		touchEnd: function(ev, e,index) {
			ev = ev || event;
			ev.preventDefault();
			if (ev.changedTouches.length == 1) {
				var endX = ev.changedTouches[0].clientX;
				this.disX = endX - this.startX;
				if (this.disX < 0) {
					// 左滑
					if(index==this.banners.length-1){
						return;
					}else{
						clearInterval(this.inter)
						this.translate = this.translate-this.picWidth;
						this.bannersRock(false);
					}
				} else if(this.disX >0) {
					// 右滑
					if(index==0){
						return;
					}else{
						clearInterval(this.inter)
						this.translate = this.translate+this.picWidth;
						this.bannersRock(false);
					}
				}else{
					return;
				}
			}
		},
	},
	mounted: function() {
		window.addEventListener("scroll", this.handerScroll, {
			passive: false
		});
		
	},
	created: function() {
		this.picWidth = window.screen.width*2;
		var share = URLParam.get("share");
		wx.showLoading({
			title: "加载中",
			mask: !0
		});
		var guid = URLParam.get('guid');
		this.$http.post(baseUrl+"wap/product/one",{
			productGuid:guid
		}).then(function(e){
			wx.hideLoading();
			var data = e.data;
			if(data.success && data.data){
				this.product = data.data;
				this.get_goods_data();
				this.getEvals();
			}
		}).catch(function(e){
			wx.hideLoading(), console.log(t), wx.showToast({
				title: "网络错误，请检查网络",
				icon: "none",
				duration: 2e3,
				mask: !0
			});
		});
		if(share){
			$(document).dialog({
				type:'confirm',
				titleText:"美匠子APP",
				position:'center',
				content:"亲！需要下载APP吗？",
				buttonTextConfirm:"想要",
				buttonTextCancel:"算了",
				onClickConfirmBtn:function(){
					window.location.href="https://app.meijiangzi.com/static/mjzapp.html";
				},
			});
		}
	}


});
